﻿using BlackBox;
using NUnit.Framework;

namespace Tests.Unit
{
    [TestFixture]
    public class WhenExecutingTrades
    {
        private const decimal InvestmentAmount = 500.0m;

        [Test]
        public void ExecuteBuyRealizesProfitCorrectly()
        {
            const decimal percentageChange = 0.01m;
            const decimal expectedProfit = InvestmentAmount * percentageChange;
            var profit = ExecutionEngine.ExecuteAndRealizeTrade( InvestmentAmount, percentageChange, MarketAction.Buy );
            
            Assert.That(profit, Is.EqualTo( expectedProfit )  );
        }

        [Test]
        public void ExecuteBuyRealizesLossCorrectly()
        {
            const decimal percentageChange = -0.01m;
            const decimal expectedProfit = InvestmentAmount * percentageChange;
            var profit = ExecutionEngine.ExecuteAndRealizeTrade(InvestmentAmount, percentageChange, MarketAction.Buy);
            
            Assert.That(profit, Is.EqualTo(expectedProfit));
        }

        [Test]
        public void ExecuteShortRealizesProfitCorrectly()
        {
            const decimal percentChange = -0.01m;
            const decimal expectedProfit = InvestmentAmount * (-percentChange);
            var profit = ExecutionEngine.ExecuteAndRealizeTrade( InvestmentAmount, percentChange, MarketAction.Short );

            Assert.That( profit, Is.EqualTo( expectedProfit ) );
        }

        [Test]
        public void ExecuteShortRealizesLossCorrectly()
        {
            const decimal percentChange = 0.01m;
            const decimal expectedProfit = InvestmentAmount * (-percentChange);
            var profit = ExecutionEngine.ExecuteAndRealizeTrade(InvestmentAmount, percentChange, MarketAction.Short);

            Assert.That(profit, Is.EqualTo(expectedProfit));
        }

        [Test]
        public void ExecuteNothingReturnsZero()
        {
            const decimal percentChange = 0.01m;
            const decimal expectedProfit = 0m;
            var profit = ExecutionEngine.ExecuteAndRealizeTrade( InvestmentAmount, percentChange, MarketAction.None );

            Assert.That( profit, Is.EqualTo( 0 ) );
        }

    }
}
